<template>
  <audio :src="audioUrl"
    style="display:none;"
    autoplay
    loop
    ref="audioRef"></audio>
</template>
<script>
import audioUrl from '@/assets/audio/alarm.mp3'
import { setTimeout } from 'timers'
export default {
  data: () => ({
    audioUrl,
    audio: null
  }),
  methods: {
    close() {
      this.$nextTick(() => {
        const audio = this.$refs.audioRef
        this.$destroy(true)
        try {
          if (audio) {
            audio.pause()
          }
          if (this.$el.parentNode) {
            this.$el.parentNode.removeChild(this.$el)
          }
        } catch (error) {
          console.log(error)
          console.log(this)
          console.log(this.$el.parentNode)
        }
      })
    },
    pause() {
      if (this.$refs.audioRef) {
        this.$refs.audioRef.pause()
      }
    },
    play() {
      if (this.$refs.audioRef) {
        this.$refs.audioRef.play()
      }
    }
  }
}
</script>

